package com.aaa.web.service.impl.carrecycleserviceimpl;

import com.aaa.entity.Employee;
import com.aaa.util.EmpUtil;
import com.aaa.web.commons.CarRecycleQuery;
import com.aaa.web.dao.carrecycledao.CarRecycleDao;
import com.aaa.web.service.carrecycleservice.CarRecycleService;
import com.aaa.web.systemconst.ISystemConst;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: battery
 * @description: 车辆回收
 * @author: liangyongzhen
 * @create: 2018-12-25 13:15
 **/
@Service
public class CarRecycleServiceImpl implements CarRecycleService {
    @Autowired
    private CarRecycleDao carRecycleDao;
    /**
    * @Description: 获取所有回收单
    * @Param: []
    * @return: java.util.List<com.aaa.entity.BackRecycle>
    * @Author: liangyongzhen
    * @Date: 2018/12/25
    */ 
    @Override
    public Map getAllCarList(CarRecycleQuery query) {

        int page = query.getPage();
        int size = query.getLimit();
        PageHelper.startPage(page,size);
        Map<String, Object> map = new HashMap<>();
        //获取所有回收电动车信息
        List<Map> allNotice = carRecycleDao.getAllCarList();
        map.put("data",allNotice);
        //获取所有回收电动车数量
        map.put("count",carRecycleDao.getCarListCount());
        map.put("code", ISystemConst.SU_COD);
        map.put("msg","");
        return map;
    }
    /**
    * @Description: 通过手机号来查找到回收申请单
    * @Param: [telephone]
    * @return: com.aaa.entity.BackRecycle
    * @Author: liangyongzhen
    * @Date: 2018/12/25
    */
    @Override
    public Map getCarListByTel(CarRecycleQuery query) {
        int page = query.getPage();
        int size = query.getLimit();
        PageHelper.startPage(page,size);
        Map<String, Object> map = new HashMap<>();
        //根据手机号获取申请单
        List<Map> list = carRecycleDao.getCarListByTel(query.getTelephone());
        map.put("data",list);
        //根据手机号获取数量
        map.put("count",carRecycleDao.getCarListCount(query.getTelephone()));
        map.put("code", ISystemConst.SU_COD);
        map.put("msg","");
        return map;
    }
    /**
    * @Description: 更新价格
    * @Param: []
    * @return: java.util.Map
    * @Author: liangyongzhen
    * @Date: 2018/12/26
    */ 
    @Override
    public Map updatePrice(CarRecycleQuery query) {
        //获取操作员工id
        Employee emp = EmpUtil.getEmp();
        query.setEmployeeid(emp.getEmployeeid());

        Map<String, Object> map = new HashMap<>();
        //更新价格
        carRecycleDao.updatePrice(query);
        //更新时间
        carRecycleDao.updateTime(query);
        map.put("code",ISystemConst.SUCCESS_CODE);
        map.put("msg","");
        return map;
    }
    /**
    * @Description: 拒绝回收单
    * @Param: [query]
    * @return: java.util.Map
    * @Author: liangyongzhen
    * @Date: 2018/12/26
    */ 
    @Override
    public Map refuseApply(CarRecycleQuery query) {
        //获取操作员工id
        Employee emp = EmpUtil.getEmp();
        query.setEmployeeid(emp.getEmployeeid());

        Map<String, Object> map = new HashMap<>();
        //驳回申请
        carRecycleDao.refuseApply(query);
        //更新时间
        carRecycleDao.updateTime(query);
        map.put("code",ISystemConst.SUCCESS_CODE);
        map.put("msg","");
        return map;
    }

    /**
    * @Description: 完成回收申请单
    * @Param: [query]
    * @return: java.util.Map
    * @Author: liangyongzhen
    * @Date: 2018/12/26
    */ 
    @Override
    public Map dealApply(CarRecycleQuery query) {
        //获取操作员工id
        Employee emp = EmpUtil.getEmp();
        query.setEmployeeid(emp.getEmployeeid());

        Map<String, Object> map = new HashMap<>();
        //同意申请
        carRecycleDao.dealApply(query);
        //更新修改时间
        carRecycleDao.updateTime(query);
        map.put("code",ISystemConst.SUCCESS_CODE);
        map.put("msg","");
        return map;
    }
    /**
    * @Description: 获取回收车辆历史
    * @Param: [query]
    * @return: java.util.Map
    * @Author: liangyongzhen
    * @Date: 2018/12/26
    */ 
    @Override
    public Map getReCycleDetail(CarRecycleQuery query) {

        int page = query.getPage();
        int size = query.getLimit();
        PageHelper.startPage(page,size);
        Map<String, Object> map = new HashMap<>();
        //获取所有回收电动车信息
        List<Map> list = carRecycleDao.getReCycleDetail(query);
        map.put("data",list);
        //获取所有回收电动车数量
        map.put("count",carRecycleDao.getCarHistoryCount());
        map.put("code", ISystemConst.SU_COD);
        map.put("msg","");
        return map;
    }
    /**
    * @Description: 根据手机号搜索历史
    * @Param: [query]
    * @return: java.util.Map
    * @Author: liangyongzhen
    * @Date: 2019/1/2
    */ 
    @Override
    public Map getCarHistoryByTel(CarRecycleQuery query) {
        int page = query.getPage();
        int size = query.getLimit();
        PageHelper.startPage(page,size);
        Map<String, Object> map = new HashMap<>();
        //根据手机号获取申请单
        List<Map> list = carRecycleDao.getCarHistoryByTel(query.getTelephone());
        map.put("data",list);
        //根据手机号获取数量
        map.put("count",carRecycleDao.getCarHistoryCount(query.getTelephone()));
        map.put("code", ISystemConst.SU_COD);
        map.put("msg","");
        return map;
    }
}
